package com.example.compreshensiveshop.controller;

import com.example.compreshensiveshop.dto.SellerCreateDTO;
import com.example.compreshensiveshop.dto.SellerUpdateDTO;
import com.example.compreshensiveshop.service.SellerService;
import com.example.compreshensiveshop.utils.QiniuKodoUtil;
import com.example.compreshensiveshop.vo.SellerVO;


import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;




@RestController
@RequestMapping("/seller")
public class SellerController {
    @Autowired
    private SellerService sellerService;
    @Autowired
    private QiniuKodoUtil qiniuKodoUtil;
    /**
     * 添加商家
     * @param sellerCreateDTO
     * @param request
     */
    @RequestMapping("/addSeller")
    public void addSeller(@RequestBody SellerCreateDTO sellerCreateDTO, HttpServletRequest request){
        Long userId = (Long) request.getAttribute("userId");
        sellerCreateDTO.setUserId(userId);
        sellerService.addSeller(sellerCreateDTO);
    }
    /**
     * 获取商家logo
     * @param logo
     * @return
     */
    @PostMapping ("/getLogoUrl")
    public String getLogoUrl(@RequestParam MultipartFile logo){
        return qiniuKodoUtil.upload(logo);
    }
    /**
     * 获取商家信息
     * @param id
     * @return
     */
    @GetMapping("/querySellerById")
    public SellerVO querySellerById(@RequestParam Long id){
        return sellerService.querySellerById(id);
    }
    /**
     * 修改商家logo
     * @param logo
     * @param sellerId
     */
    @PutMapping("/updateLogo")
    public void updateLogo(@RequestParam MultipartFile logo, @RequestParam Long sellerId){
        String logoUrl = qiniuKodoUtil.upload(logo);
        sellerService.updateLogo(sellerId, logoUrl);
    }
    /**
     * 修改商家信息
     * @param sellerUpdateDTO
     */
    @PutMapping("updateMessage")
    public void updateMessage(@RequestBody SellerUpdateDTO sellerUpdateDTO){
        sellerService.updateMessage(sellerUpdateDTO);
    }

}